

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="z">
  <meta name="keywords" content="linux,docker,nginx,jar,java,sh,jdk">
  
    <meta name="description" content="1、Linux 安装Nginx并支持SSL,开机启动下载依赖123yum -y install gcc gcc-c++ autoconf automake libtool make cmakeyum -y install zlib zlib-devel openssl openssl-devel pcre-devel  安装编译1234567wget http:&#x2F;&#x2F;nginx.org&#x2F;downlo">
<meta property="og:type" content="article">
<meta property="og:title" content="linux环境初始化">
<meta property="og:url" content="https://hexo.xy94.top/2022/linux%E7%8E%AF%E5%A2%83%E5%88%9D%E5%A7%8B%E5%8C%96.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="1、Linux 安装Nginx并支持SSL,开机启动下载依赖123yum -y install gcc gcc-c++ autoconf automake libtool make cmakeyum -y install zlib zlib-devel openssl openssl-devel pcre-devel  安装编译1234567wget http:&#x2F;&#x2F;nginx.org&#x2F;downlo">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-03-25T02:27:00.000Z">
<meta property="article:modified_time" content="2024-02-01T02:29:17.611Z">
<meta property="article:author" content="z">
<meta property="article:tag" content="java">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="docker">
<meta property="article:tag" content="nginx">
<meta property="article:tag" content="jar">
<meta property="article:tag" content="sh">
<meta property="article:tag" content="jdk">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>linux环境初始化 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"hexo.xy94.top","root":"/","version":"1.9.7","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>个人分享</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/" target="_self">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/" target="_self">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/" target="_self">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/" target="_self">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/" target="_self">
                <i class="iconfont icon-user-fill"></i>
                <span>联系我</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/" target="_self">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" href="javascript:;" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-books"></i>
                <span>文档</span>
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" href="https://hexo.fluid-dev.com/" target="_self">
                    
                    <span>主题博客</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="https://hexo.fluid-dev.com/docs/guide/" target="_self">
                    
                    <span>配置指南</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="https://hexo.fluid-dev.com/docs/icon/" target="_self">
                    
                    <span>图标用法</span>
                  </a>
                
              </div>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="linux环境初始化"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        z
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-03-25 10:27" pubdate>
          2022-03-25 10:27:00 星期五 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          <!-- compatible with older versions-->
          958 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          <!-- compatible with older versions-->
          8 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>
<meta name="baidu-site-verification" content="codeva-jcIBX7fHxH" />
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">linux环境初始化</h1>
            
            
              <div class="markdown-body">
                
                <h2 id="1、Linux-安装Nginx并支持SSL-开机启动"><a href="#1、Linux-安装Nginx并支持SSL-开机启动" class="headerlink" title="1、Linux 安装Nginx并支持SSL,开机启动"></a>1、Linux 安装Nginx并支持SSL,开机启动</h2><h3 id="下载依赖"><a href="#下载依赖" class="headerlink" title="下载依赖"></a>下载依赖</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sh">yum -y install gcc gcc-c++ autoconf automake libtool make cmake<br>yum -y install zlib zlib-devel openssl openssl-devel pcre-devel<br><br></code></pre></td></tr></table></figure>

<h3 id="安装编译"><a href="#安装编译" class="headerlink" title="安装编译"></a>安装编译</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs sh">wget http://nginx.org/download/nginx-1.15.7.tar.gz<br>tar -zxvf nginx-1.15.7.tar.gz -C /home/<br><span class="hljs-built_in">cd</span> /home/nginx-1.15.7/<br>./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre<br>make<br>make install<br><br></code></pre></td></tr></table></figure>


<h3 id="常规操作"><a href="#常规操作" class="headerlink" title="常规操作"></a>常规操作</h3><figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs swift">[root<span class="hljs-meta">@localhost</span> <span class="hljs-operator">~</span>]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/nginx/</span>sbin<span class="hljs-operator">/</span>nginx   启动<br>[root<span class="hljs-meta">@localhost</span> <span class="hljs-operator">~</span>]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/nginx/</span>sbin<span class="hljs-operator">/</span>nginx <span class="hljs-operator">-</span>s stop  停止<br>[root<span class="hljs-meta">@localhost</span> <span class="hljs-operator">~</span>]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/nginx/</span>sbin<span class="hljs-operator">/</span>nginx <span class="hljs-operator">-</span>s reload  重新载入<br>[root<span class="hljs-meta">@localhost</span> <span class="hljs-operator">~</span>]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/nginx/</span>sbin<span class="hljs-operator">/</span>nginx <span class="hljs-operator">-</span>v  查看版本<br>[root<span class="hljs-meta">@localhost</span> <span class="hljs-operator">~</span>]# <span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/nginx/</span>sbin<span class="hljs-operator">/</span>nginx <span class="hljs-operator">-</span>t  测试配置文件是否正常<br><br></code></pre></td></tr></table></figure>

<h3 id="开机启动"><a href="#开机启动" class="headerlink" title="开机启动"></a>开机启动</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br></pre></td><td class="code"><pre><code class="hljs sh">vim /etc/init.d/nginx<br><br><span class="hljs-comment">#!/bin/sh</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># nginx - this script starts and stops the nginx daemon</span><br><span class="hljs-comment">#</span><br><span class="hljs-comment"># chkconfig:   - 85 15</span><br><span class="hljs-comment"># description:  NGINX is an HTTP(S) server, HTTP(S) reverse \</span><br><span class="hljs-comment">#               proxy and IMAP/POP3 proxy server</span><br><span class="hljs-comment"># processname: nginx</span><br><span class="hljs-comment"># config:      /etc/nginx/nginx.conf</span><br><span class="hljs-comment"># config:      /etc/sysconfig/nginx</span><br><span class="hljs-comment"># pidfile:     /var/run/nginx.pid</span><br><br><span class="hljs-comment"># Source function library.</span><br>. /etc/rc.d/init.d/functions<br><br><span class="hljs-comment"># Source networking configuration.</span><br>. /etc/sysconfig/network<br><br><span class="hljs-comment"># Check that networking is up.</span><br>[ <span class="hljs-string">&quot;<span class="hljs-variable">$NETWORKING</span>&quot;</span> = <span class="hljs-string">&quot;no&quot;</span> ] &amp;&amp; <span class="hljs-built_in">exit</span> 0<br><br>nginx=<span class="hljs-string">&quot;/usr/local/nginx/sbin/nginx&quot;</span><br>prog=$(<span class="hljs-built_in">basename</span> <span class="hljs-variable">$nginx</span>)<br><br>NGINX_CONF_FILE=<span class="hljs-string">&quot;/usr/local/nginx/conf/nginx.conf&quot;</span><br><br>[ -f /etc/sysconfig/nginx ] &amp;&amp; . /etc/sysconfig/nginx<br><br>lockfile=/var/lock/subsys/nginx<br><br><span class="hljs-function"><span class="hljs-title">make_dirs</span></span>() &#123;<br>   <span class="hljs-comment"># make required directories</span><br>   user=`<span class="hljs-variable">$nginx</span> -V 2&gt;&amp;1 | grep <span class="hljs-string">&quot;configure arguments:.*--user=&quot;</span> | sed <span class="hljs-string">&#x27;s/[^*]*--user=\([^ ]*\).*/\1/g&#x27;</span> -`<br>   <span class="hljs-keyword">if</span> [ -n <span class="hljs-string">&quot;<span class="hljs-variable">$user</span>&quot;</span> ]; <span class="hljs-keyword">then</span><br>      <span class="hljs-keyword">if</span> [ -z <span class="hljs-string">&quot;`grep <span class="hljs-variable">$user</span> /etc/passwd`&quot;</span> ]; <span class="hljs-keyword">then</span><br>         useradd -M -s /bin/nologin <span class="hljs-variable">$user</span><br>      <span class="hljs-keyword">fi</span><br>      options=`<span class="hljs-variable">$nginx</span> -V 2&gt;&amp;1 | grep <span class="hljs-string">&#x27;configure arguments:&#x27;</span>`<br>      <span class="hljs-keyword">for</span> opt <span class="hljs-keyword">in</span> <span class="hljs-variable">$options</span>; <span class="hljs-keyword">do</span><br>          <span class="hljs-keyword">if</span> [ `<span class="hljs-built_in">echo</span> <span class="hljs-variable">$opt</span> | grep <span class="hljs-string">&#x27;.*-temp-path&#x27;</span>` ]; <span class="hljs-keyword">then</span><br>              value=`<span class="hljs-built_in">echo</span> <span class="hljs-variable">$opt</span> | <span class="hljs-built_in">cut</span> -d <span class="hljs-string">&quot;=&quot;</span> -f 2`<br>              <span class="hljs-keyword">if</span> [ ! -d <span class="hljs-string">&quot;<span class="hljs-variable">$value</span>&quot;</span> ]; <span class="hljs-keyword">then</span><br>                  <span class="hljs-comment"># echo &quot;creating&quot; $value</span><br>                  <span class="hljs-built_in">mkdir</span> -p <span class="hljs-variable">$value</span> &amp;&amp; <span class="hljs-built_in">chown</span> -R <span class="hljs-variable">$user</span> <span class="hljs-variable">$value</span><br>              <span class="hljs-keyword">fi</span><br>          <span class="hljs-keyword">fi</span><br>       <span class="hljs-keyword">done</span><br>    <span class="hljs-keyword">fi</span><br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">start</span></span>() &#123;<br>    [ -x <span class="hljs-variable">$nginx</span> ] || <span class="hljs-built_in">exit</span> 5<br>    [ -f <span class="hljs-variable">$NGINX_CONF_FILE</span> ] || <span class="hljs-built_in">exit</span> 6<br>    make_dirs<br>    <span class="hljs-built_in">echo</span> -n $<span class="hljs-string">&quot;Starting <span class="hljs-variable">$prog</span>: &quot;</span><br>    daemon <span class="hljs-variable">$nginx</span> -c <span class="hljs-variable">$NGINX_CONF_FILE</span><br>    retval=$?<br>    <span class="hljs-built_in">echo</span><br>    [ <span class="hljs-variable">$retval</span> -eq 0 ] &amp;&amp; <span class="hljs-built_in">touch</span> <span class="hljs-variable">$lockfile</span><br>    <span class="hljs-built_in">return</span> <span class="hljs-variable">$retval</span><br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">stop</span></span>() &#123;<br>    <span class="hljs-built_in">echo</span> -n $<span class="hljs-string">&quot;Stopping <span class="hljs-variable">$prog</span>: &quot;</span><br>    killproc <span class="hljs-variable">$prog</span> -QUIT<br>    retval=$?<br>    <span class="hljs-built_in">echo</span><br>    [ <span class="hljs-variable">$retval</span> -eq 0 ] &amp;&amp; <span class="hljs-built_in">rm</span> -f <span class="hljs-variable">$lockfile</span><br>    <span class="hljs-built_in">return</span> <span class="hljs-variable">$retval</span><br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">restart</span></span>() &#123;<br>    configtest || <span class="hljs-built_in">return</span> $?<br>    stop<br>    <span class="hljs-built_in">sleep</span> 1<br>    start<br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">reload</span></span>() &#123;<br>    configtest || <span class="hljs-built_in">return</span> $?<br>    <span class="hljs-built_in">echo</span> -n $<span class="hljs-string">&quot;Reloading <span class="hljs-variable">$prog</span>: &quot;</span><br>    killproc <span class="hljs-variable">$nginx</span> -HUP<br>    RETVAL=$?<br>    <span class="hljs-built_in">echo</span><br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">force_reload</span></span>() &#123;<br>    restart<br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">configtest</span></span>() &#123;<br>  <span class="hljs-variable">$nginx</span> -t -c <span class="hljs-variable">$NGINX_CONF_FILE</span><br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">rh_status</span></span>() &#123;<br>    status <span class="hljs-variable">$prog</span><br>&#125;<br><br><span class="hljs-function"><span class="hljs-title">rh_status_q</span></span>() &#123;<br>    rh_status &gt;/dev/null 2&gt;&amp;1<br>&#125;<br><br><span class="hljs-keyword">case</span> <span class="hljs-string">&quot;<span class="hljs-variable">$1</span>&quot;</span> <span class="hljs-keyword">in</span><br>    start)<br>        rh_status_q &amp;&amp; <span class="hljs-built_in">exit</span> 0<br>        <span class="hljs-variable">$1</span><br>        ;;<br>    stop)<br>        rh_status_q || <span class="hljs-built_in">exit</span> 0<br>        <span class="hljs-variable">$1</span><br>        ;;<br>    restart|configtest)<br>        <span class="hljs-variable">$1</span><br>        ;;<br>    reload)<br>        rh_status_q || <span class="hljs-built_in">exit</span> 7<br>        <span class="hljs-variable">$1</span><br>        ;;<br>    force-reload)<br>        force_reload<br>        ;;<br>    status)<br>        rh_status<br>        ;;<br>    condrestart|try-restart)<br>        rh_status_q || <span class="hljs-built_in">exit</span> 0<br>            ;;<br>    *)<br>        <span class="hljs-built_in">echo</span> $<span class="hljs-string">&quot;Usage: <span class="hljs-variable">$0</span> &#123;start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest&#125;&quot;</span><br>        <span class="hljs-built_in">exit</span> 2<br><span class="hljs-keyword">esac</span><br><br><br><span class="hljs-built_in">chmod</span> a+x nginx<br><br><br>chkconfig --add /etc/init.d/nginx<br><br>service nginx start //开户nginx<br>service nginx stop //关闭nginx<br><br>chkconfig nginx on<br><br><br><br></code></pre></td></tr></table></figure>


<h2 id="2、jdk8"><a href="#2、jdk8" class="headerlink" title="2、jdk8"></a>2、jdk8</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs sh">wget --no-check-certificate --no-cookies --header <span class="hljs-string">&quot;Cookie: oraclelicense=accept-securebackup-cookie&quot;</span> http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm<br><br><span class="hljs-built_in">chmod</span> +x jdk-8u131-linux-x64.rpm<br><br>rpm -ivh jdk-8u131-linux-x64.rpm<br><br>java -version<br><br></code></pre></td></tr></table></figure>

<h3 id="环境变量配置"><a href="#环境变量配置" class="headerlink" title="环境变量配置"></a>环境变量配置</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs sh">vi /etc/profile<br>在文件的最后添上如下命令<br><span class="hljs-built_in">export</span> JAVA_HOME=/usr/java/jdk1.8.0_131	<br><span class="hljs-built_in">export</span> JRE_HOME=<span class="hljs-variable">$&#123;JAVA_HOME&#125;</span>/jre<br><span class="hljs-built_in">export</span> CLASSPATH=.:<span class="hljs-variable">$&#123;JAVA_HOME&#125;</span>/lib:<span class="hljs-variable">$&#123;JRE_HOME&#125;</span>/lib:<span class="hljs-variable">$CLASSPATH</span><br><span class="hljs-built_in">export</span> JAVA_PATH=<span class="hljs-variable">$&#123;JAVA_HOME&#125;</span>/bin:<span class="hljs-variable">$&#123;JRE_HOME&#125;</span>/bin<br><span class="hljs-built_in">export</span> PATH=<span class="hljs-variable">$PATH</span>:<span class="hljs-variable">$&#123;JAVA_PATH&#125;</span><br><br><span class="hljs-built_in">source</span> /etc/profile<br><br><br></code></pre></td></tr></table></figure>
<h3 id="验证"><a href="#验证" class="headerlink" title="验证"></a>验证</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sh">javac<br></code></pre></td></tr></table></figure>

<h2 id="3、上传下载"><a href="#3、上传下载" class="headerlink" title="3、上传下载"></a>3、上传下载</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sh">yum -y install lrzsz<br></code></pre></td></tr></table></figure>


<h2 id="4、docker"><a href="#4、docker" class="headerlink" title="4、docker"></a>4、docker</h2><h3 id="Linux-安装-docker"><a href="#Linux-安装-docker" class="headerlink" title="Linux 安装 docker"></a>Linux 安装 docker</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs sh">1、yum install -y yum-utils device-mapper-persistent-data lvm2；<br><br>2、yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo<br>yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo<br><br>3、yum install docker-ce<br><br>4、systemctl start docker<br><br>5、docker run hello-world<br><br></code></pre></td></tr></table></figure>


<h3 id="docker命令"><a href="#docker命令" class="headerlink" title="docker命令"></a>docker命令</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs sh">docker images 查看本地镜像列表<br>docker search &lt;images name&gt;<br>docker pull &lt;域名&gt;/&lt;namespace&gt;/&lt;repo&gt;:&lt;tag&gt;<br>docker inspect &lt;image_id&gt;<br>docker rmi &lt;images&gt;:&lt;tag&gt;<br>docker commit &lt;options&gt; &lt;container_id&gt; &lt;repository:tag&gt;<br>docker save -o &lt;image&gt;.tar &lt;image&gt;:&lt;tag&gt;<br>docker load --input &lt;image&gt;.tar<br>docker push &lt;域名&gt;/&lt;namespace&gt;/&lt;repo&gt;:&lt;tag&gt;<br><br></code></pre></td></tr></table></figure>

<h3 id="docker-启动MySQL服务"><a href="#docker-启动MySQL服务" class="headerlink" title="docker 启动MySQL服务"></a>docker 启动MySQL服务</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs sh">docker run --name some-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=12345678 --restart=always -v /var/lib/mysql:/var/lib/mysql -d mysql:8.0.27<br>docker run --name some-mysql -v ~/.halo/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=12345678 --net host --restart=unless-stopped -d mysql:8.0.27<br>docker run -it -d --name halo -p 8090:8090 -v ~/.halo:/root/.halo --net host --restart=unless-stopped halohub/halo:1.4.17<br>开机启动镜像<br>docker update --restart=always <span class="hljs-string">&quot;镜像id或容器别名&quot;</span><br><br>关闭自动开启：<br>docker update --restart=no <span class="hljs-string">&quot;镜像id或镜像别名&quot;</span><br><br></code></pre></td></tr></table></figure>


<h2 id="5-nohub"><a href="#5-nohub" class="headerlink" title="5.nohub"></a>5.nohub</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sh"><span class="hljs-built_in">nohup</span> java -jar app-1.0-SNAPSHOT.jar &gt;&gt;app.log 2&gt;&amp;1 $<br><br></code></pre></td></tr></table></figure>



<h2 id="6、jar开机自启动"><a href="#6、jar开机自启动" class="headerlink" title="6、jar开机自启动"></a>6、jar开机自启动</h2><h3 id="编辑-sh脚本"><a href="#编辑-sh脚本" class="headerlink" title="编辑 .sh脚本"></a>编辑 .sh脚本</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs sh">vim run-app.sh<br><br><span class="hljs-comment"># run-app.sh内容</span><br>appname=<span class="hljs-string">&#x27;blog-1.0.jar&#x27;</span><br>pid=$(ps -ef|grep blog-1.0.jar |grep -v grep|awk <span class="hljs-string">&quot;&#123;print \$2&#125;&quot;</span>)<br><span class="hljs-keyword">if</span> [ ! <span class="hljs-string">&quot;<span class="hljs-variable">$&#123;pid&#125;</span>&quot;</span> ];<span class="hljs-keyword">then</span><br>	<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;没有找到<span class="hljs-variable">$&#123;appname&#125;</span>的进程,无需kill&quot;</span><br><span class="hljs-keyword">else</span><br>	<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;找到<span class="hljs-variable">$&#123;appname&#125;</span>的进程<span class="hljs-variable">$&#123;pid&#125;</span>&quot;</span><br>	<span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;kill <span class="hljs-variable">$&#123;pid&#125;</span>&quot;</span><br>	<span class="hljs-built_in">kill</span> -9 <span class="hljs-variable">$&#123;pid&#125;</span><br><span class="hljs-keyword">fi</span><br><br><span class="hljs-built_in">nohup</span> java -jar /app/blog/blog-1.0.jar &gt;&gt; /app/blog/log/blog-1.0.<span class="hljs-built_in">log</span> &amp;2&gt;1 &amp;<br><br>newpid=$(ps -ef|grep blog-1.0.jar |grep -v grep |awk <span class="hljs-string">&quot;&#123;print \$2&#125;&quot;</span>)<br><span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;启动完毕，进程<span class="hljs-variable">$&#123;newpid&#125;</span>&quot;</span><br><span class="hljs-built_in">tail</span> -f ./log/blog-1.0.<span class="hljs-built_in">log</span><br><br></code></pre></td></tr></table></figure>
<figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs stata">chmod 777 <span class="hljs-keyword">run</span>-<span class="hljs-keyword">app</span>.<span class="hljs-keyword">sh</span><br>vim /etc/rc.<span class="hljs-keyword">d</span>/rc.<span class="hljs-keyword">local</span> <span class="hljs-comment">//添加</span><br><span class="hljs-keyword">sh</span> /root/<span class="hljs-keyword">run</span>-<span class="hljs-keyword">app</span>.<span class="hljs-keyword">sh</span> &gt;&gt;/root/<span class="hljs-keyword">app</span>.<span class="hljs-keyword">log</span><br><br></code></pre></td></tr></table></figure>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/linux/" class="category-chain-item">linux</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/java/" class="print-no-link">#java</a>
      
        <a href="/tags/linux/" class="print-no-link">#linux</a>
      
        <a href="/tags/docker/" class="print-no-link">#docker</a>
      
        <a href="/tags/nginx/" class="print-no-link">#nginx</a>
      
        <a href="/tags/jar/" class="print-no-link">#jar</a>
      
        <a href="/tags/sh/" class="print-no-link">#sh</a>
      
        <a href="/tags/jdk/" class="print-no-link">#jdk</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>linux环境初始化</div>
      <div>https://hexo.xy94.top/2022/linux环境初始化.html</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>z</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年3月25日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/mysql%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E9%85%8D%E7%BD%AE.html" title="mysql主从复制配置">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">mysql主从复制配置</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/%E8%AE%B0%E4%B8%80%E6%AC%A1nginx%E6%97%A5%E5%BF%97%E8%AF%BB%E5%86%99%E6%97%A0%E6%9D%83%E9%99%90%E9%97%AE%E9%A2%98.html" title="nginx无法自主创建日志文件和写入日志">
                        <span class="hidden-mobile">nginx无法自主创建日志文件和写入日志</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
